"""
__author__ = 'berlinyoung'
@File   :market_page.py
@Date   :2022/6/12 21:53
-*- coding: utf-8 -*-
"""
import time

from appium.webdriver.common.mobileby import MobileBy

from anxinstock_mobile.page.base import Base
from anxinstock_mobile.page.single_stock_page import SingleStockPage


class MarketPage(Base):

    def Check_optional(self,name):
        # # 查看上证指数
        # self.find(MobileBy.ID,"tv_one_price").get_attribute("text")
        # # 查看创业指数
        # self.find(MobileBy.ID,"tv_two_price").get_attribute("text")
        # 查看个股指数
        self.find_and_click(MobileBy.XPATH,"//*[@text='自选']")
        result_one = self.find_get(MobileBy.XPATH,f"//*[@text='{name}']/../..//*[@resource-id='cn.com.essence.stock:id/price_new']")

        return result_one

    def Check_optional_multi(self,name1,name2):
        # # 查看上证指数
        # self.find(MobileBy.ID,"tv_one_price").get_attribute("text")
        # # 查看创业指数
        # self.find(MobileBy.ID,"tv_two_price").get_attribute("text")
        result_multi = []
        # 查看个股指数
        self.find_and_click(MobileBy.XPATH,"//*[@text='自选']")
        for i in [name1,name2]:
            result = self.find_get(MobileBy.XPATH,f"//*[@text='{i}']/../..//*[@resource-id='cn.com.essence.stock:id/price_new']")
            result_multi.append(result)

        return result_multi

    def goto_single_stock(self,name):
        # 进入个股
        self.find_and_click(MobileBy.XPATH,f"//*[@text='{name}']")
        return SingleStockPage(self.driver)